﻿namespace DALFactory
{
    using IDal.Comm;
    using IDal.Company;
    using IDal.Guest;
    using IDal.Processing;
    using IDal.Procurement;
    using IDal.Sales;
    using IDal.Stock;
    using IDal.Supplier;
    using IDal.Systems;
    using System;
    using System.Reflection;
    using System.Configuration;

    public class DataAccess
    {
        private static readonly string path = ConfigurationManager.AppSettings["SQLServerDAL"];

        public static IChain CreateChain()
        {
            string cacheKey = path + ".Systems.ChainApp";
            return (IChain) CreateObjectCache(path, cacheKey);
        }

        public static IComm CreateComm()
        {
            string cacheKey = path + ".Comm.CommApp";
            return (IComm) CreateObjectCache(path, cacheKey);
        }

        public static ICommType CreateCommType()
        {
            string cacheKey = path + ".Comm.CommTypeApp";
            return (ICommType) CreateObjectCache(path, cacheKey);
        }

        public static ICompayAccount CreateCompayAccount()
        {
            string cacheKey = path + ".Company.CompayAccountApp";
            return (ICompayAccount) CreateObjectCache(path, cacheKey);
        }

        public static ICompayAccountDetails CreateCompayAccountDetails()
        {
            string cacheKey = path + ".Company.CompayAccountDetailsApp";
            return (ICompayAccountDetails) CreateObjectCache(path, cacheKey);
        }

        public static IConfig CreateConfig()
        {
            string cacheKey = path + ".Systems.ConfigApp";
            return (IConfig) CreateObjectCache(path, cacheKey);
        }

        public static IDamageReported CreateDamageReported()
        {
            string cacheKey = path + ".Stock.DamageReportedApp";
            return (IDamageReported) CreateObjectCache(path, cacheKey);
        }

        public static IDamageReportedComm CreateDamageReportedComm()
        {
            string cacheKey = path + ".Stock.DamageReportedCommApp";
            return (IDamageReportedComm) CreateObjectCache(path, cacheKey);
        }

        public static IDept CreateDept()
        {
            string cacheKey = path + ".Systems.DeptApp";
            return (IDept) CreateObjectCache(path, cacheKey);
        }

        public static IDigitallibrary CreateDigitallibrary()
        {
            string cacheKey = path + ".Stock.DigitallibraryApp";
            return (IDigitallibrary) CreateObjectCache(path, cacheKey);
        }

        public static IErrors CreateErrors()
        {
            string cacheKey = path + ".Systems.ErrorsApp";
            return (IErrors) CreateObjectCache(path, cacheKey);
        }

        public static IGetTableColCount CreateGetTableColCount()
        {
            string cacheKey = path + ".Systems.GetTableColCountApp";
            return (IGetTableColCount) CreateObjectCache(path, cacheKey);
        }

        public static IGoodsInOut CreateGoodsInOut()
        {
            string cacheKey = path + ".Stock.GoodsInOutApp";
            return (IGoodsInOut) CreateObjectCache(path, cacheKey);
        }

        public static IGuest CreateGuest()
        {
            string cacheKey = path + ".Guest.GuestApp";
            return (IGuest) CreateObjectCache(path, cacheKey);
        }

        public static IGuestGrade CreateGuestGrade()
        {
            string cacheKey = path + ".Guest.GuestGradeApp";
            return (IGuestGrade) CreateObjectCache(path, cacheKey);
        }

        public static Ihelps Createhelps()
        {
            string cacheKey = path + ".Systems.helpsApp";
            return (Ihelps) CreateObjectCache(path, cacheKey);
        }

        public static IIdocumentCode CreateIdocumentCode()
        {
            string cacheKey = path + ".Systems.IdocumentCodeApp";
            return (IIdocumentCode) CreateObjectCache(path, cacheKey);
        }

        public static IInventory CreateInventory()
        {
            string cacheKey = path + ".Stock.InventoryApp";
            return (IInventory) CreateObjectCache(path, cacheKey);
        }

        public static IInventoryComm CreateInventoryComm()
        {
            string cacheKey = path + ".Stock.InventoryCommApp";
            return (IInventoryComm) CreateObjectCache(path, cacheKey);
        }

        public static ILibraryDetailsComm CreateLibraryDetailsComm()
        {
            string cacheKey = path + ".Stock.LibraryDetailsCommApp";
            return (ILibraryDetailsComm) CreateObjectCache(path, cacheKey);
        }

        public static ILogistics CreateLogistics()
        {
            string cacheKey = path + ".Systems.LogisticsApp";
            return (ILogistics) CreateObjectCache(path, cacheKey);
        }

        public static IMenuLinkRole CreateMenuLinkRole()
        {
            string cacheKey = path + ".Systems.MenuLinkRoleApp";
            return (IMenuLinkRole) CreateObjectCache(path, cacheKey);
        }

        public static IMenuList CreateMenuList()
        {
            string cacheKey = path + ".Systems.MenuListApp";
            return (IMenuList) CreateObjectCache(path, cacheKey);
        }

        public static INews CreateNews()
        {
            string cacheKey = path + ".Systems.NewsApp";
            return (INews) CreateObjectCache(path, cacheKey);
        }

        public static object CreateObjectCache(string path, string CacheKey)
        {
            object obj3;
            try
            {
                object cache = DataCache.GetCache(CacheKey);
                if (cache == null)
                {
                    cache = Assembly.Load(path).CreateInstance(CacheKey);
                    DataCache.SetCache(CacheKey, cache);
                }
                obj3 = cache;
            }
            catch (Exception exception)
            {
                throw exception;
            }
            return obj3;
        }

        public static object CreateObjectNoCache(string path, string CacheKey)
        {
            try
            {
                return Assembly.Load(path).CreateInstance(CacheKey);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public static IOrderPayment CreateOrderPayment()
        {
            string cacheKey = path + ".Sales.OrderPaymentApp";
            return (IOrderPayment) CreateObjectCache(path, cacheKey);
        }

        public static IOrders CreateOrders()
        {
            string cacheKey = path + ".Sales.OrdersApp";
            return (IOrders) CreateObjectCache(path, cacheKey);
        }

        public static IOrdersComm CreateOrdersComm()
        {
            string cacheKey = path + ".Sales.OrdersCommApp";
            return (IOrdersComm) CreateObjectCache(path, cacheKey);
        }

        public static IOrdersPayMentList CreateOrdersPayMentList()
        {
            string cacheKey = path + ".Sales.OrdersPayMentListApp";
            return (IOrdersPayMentList) CreateObjectCache(path, cacheKey);
        }

        public static IOverflowReported CreateOverflowReported()
        {
            string cacheKey = path + ".Stock.OverflowReportedApp";
            return (IOverflowReported) CreateObjectCache(path, cacheKey);
        }

        public static IOverflowReportedComm CreateOverflowReportedComm()
        {
            string cacheKey = path + ".Stock.OverflowReportedCommApp";
            return (IOverflowReportedComm) CreateObjectCache(path, cacheKey);
        }

        public static IPackagingFormula CreatePackagingFormula()
        {
            string cacheKey = path + ".Processing.PackagingFormulaApp";
            return (IPackagingFormula) CreateObjectCache(path, cacheKey);
        }

        public static IPackagingFormulaInfo CreatePackagingFormulaInfo()
        {
            string cacheKey = path + ".Processing.PackagingFormulaInfoApp";
            return (IPackagingFormulaInfo) CreateObjectCache(path, cacheKey);
        }

        public static IParameter CreateParameter()
        {
            string cacheKey = path + ".Systems.ParameterApp";
            return (IParameter) CreateObjectCache(path, cacheKey);
        }

        public static IPopdomValue CreatePopdomValue()
        {
            string cacheKey = path + ".Systems.PopdomValueApp";
            return (IPopdomValue) CreateObjectCache(path, cacheKey);
        }

        public static IPopedomTemp CreatePopedomTemp()
        {
            string cacheKey = path + ".Systems.PopedomTempApp";
            return (IPopedomTemp) CreateObjectCache(path, cacheKey);
        }

        public static IPringDocumentSet CreatePringDocumentSet()
        {
            string cacheKey = path + ".Systems.PringDocumentSetApp";
            return (IPringDocumentSet) CreateObjectCache(path, cacheKey);
        }

        public static IPrintSetting CreatePrintSetting()
        {
            string cacheKey = path + ".Systems.PrintSettingApp";
            return (IPrintSetting) CreateObjectCache(path, cacheKey);
        }

        public static IProcurement CreateProcurement()
        {
            string cacheKey = path + ".Procurement.ProcurementApp";
            return (IProcurement) CreateObjectCache(path, cacheKey);
        }

        public static IProcurementCommBuy CreateProcurementCommBuy()
        {
            string cacheKey = path + ".Procurement.ProcurementCommBuyApp";
            return (IProcurementCommBuy) CreateObjectCache(path, cacheKey);
        }

        public static IProcurementPayment CreateProcurementPayment()
        {
            string cacheKey = path + ".Procurement.ProcurementPaymentApp";
            return (IProcurementPayment) CreateObjectCache(path, cacheKey);
        }

        public static IProcurementPaymentList CreateProcurementPaymentList()
        {
            string cacheKey = path + ".Procurement.ProcurementPaymentListApp";
            return (IProcurementPaymentList) CreateObjectCache(path, cacheKey);
        }

        public static IProfitAndLoss CreateProfitAndLoss()
        {
            string cacheKey = path + ".Company.ProfitAndLossApp";
            return (IProfitAndLoss) CreateObjectCache(path, cacheKey);
        }

        public static IRole CreateRole()
        {
            string cacheKey = path + ".Systems.RoleApp";
            return (IRole) CreateObjectCache(path, cacheKey);
        }

        public static IRolePopedom CreateRolePopedom()
        {
            string cacheKey = path + ".Systems.RolePopedomApp";
            return (IRolePopedom) CreateObjectCache(path, cacheKey);
        }

        public static IStock CreateStock()
        {
            string cacheKey = path + ".Stock.StockApp";
            return (IStock) CreateObjectCache(path, cacheKey);
        }

        public static IStockAllocation CreateStockAllocation()
        {
            string cacheKey = path + ".Stock.StockAllocationApp";
            return (IStockAllocation) CreateObjectCache(path, cacheKey);
        }

        public static IStockWarning CreateStockWarning()
        {
            string cacheKey = path + ".Stock.StockWarningApp";
            return (IStockWarning) CreateObjectCache(path, cacheKey);
        }

        public static ISupplier CreateSupplier()
        {
            string cacheKey = path + ".Supplier.SupplierApp";
            return (ISupplier) CreateObjectCache(path, cacheKey);
        }

        public static ITeaMixed CreateTeaMixed()
        {
            string cacheKey = path + ".Processing.TeaMixedApp";
            return (ITeaMixed) CreateObjectCache(path, cacheKey);
        }

        public static ITeaMixedComm CreateTeaMixedComm()
        {
            string cacheKey = path + ".Processing.TeaMixedCommApp";
            return (ITeaMixedComm) CreateObjectCache(path, cacheKey);
        }

        public static ITeaPackaging CreateTeaPackaging()
        {
            string cacheKey = path + ".Processing.TeaPackagingApp";
            return (ITeaPackaging) CreateObjectCache(path, cacheKey);
        }

        public static ITeaPackagingComm CreateTeaPackagingComm()
        {
            string cacheKey = path + ".Processing.TeaPackagingCommApp";
            return (ITeaPackagingComm) CreateObjectCache(path, cacheKey);
        }

        public static ITeaProcessing CreateTeaProcessing()
        {
            string cacheKey = path + ".Processing.TeaProcessingApp";
            return (ITeaProcessing) CreateObjectCache(path, cacheKey);
        }

        public static ITeaProcessingComm CreateTeaProcessingComm()
        {
            string cacheKey = path + ".Processing.TeaProcessingCommApp";
            return (ITeaProcessingComm) CreateObjectCache(path, cacheKey);
        }

        public static ITestDunk CreateTestDunk()
        {
            string cacheKey = path + ".Sales.TestDunkApp";
            return (ITestDunk) CreateObjectCache(path, cacheKey);
        }

        public static ITestDunkComm CreateTestDunkComm()
        {
            string cacheKey = path + ".Sales.TestDunkCommApp";
            return (ITestDunkComm) CreateObjectCache(path, cacheKey);
        }

        public static IUser CreateUser()
        {
            string cacheKey = path + ".Systems.UserApp";
            return (IUser) CreateObjectCache(path, cacheKey);
        }

        public static IUserInfo CreateUserInfo()
        {
            string cacheKey = path + ".Systems.UserInfoApp";
            return (IUserInfo) CreateObjectCache(path, cacheKey);
        }

        public static IWorkLog CreateWorkLog()
        {
            string cacheKey = path + ".Systems.WorkLogApp";
            return (IWorkLog) CreateObjectCache(path, cacheKey);
        }
    }
}

